package com.my.study.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author: yidujun
 * @create: 2021/11/16 14:32
 */
@RestController
public class DownloadController {

    @Autowired
    RestTemplate restTemplate;

    private static final String URL = "http://e.thsi.cn/timg/a1da56e05339f5393fbfedb1a7a94171";

    @GetMapping("/download")
    public ResponseEntity<byte[]> download() {
        ResponseEntity<byte[]> entity = restTemplate.getForEntity(URL, byte[].class);
        byte[] body = entity.getBody();
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.set("Content-Type", "image/jpeg");
        return new ResponseEntity<>(body, httpHeaders, HttpStatus.OK);
    }

}
